﻿
Imports System.Data

Imports Moca.Db.Attr
Imports Moca.Db

Namespace Db.Impl

#Region " SQL "

	Public Class DaoSql
		Inherits AbstractDao
		Implements IDaoSqlTest

		Protected dao As IDaoSqlTest2

#Region " Logging For Log4net "
		''' <summary>Logging For Log4net</summary>
		Private ReadOnly _mylog As log4net.ILog = log4net.LogManager.GetLogger(String.Empty)
#End Region

#Region " コンストラクタ "

		'Public Sub New(ByVal value As String)
		'	MyBase.New(New Dbms(value))
		'End Sub

#End Region

		Public Sub Ins(id As Integer) Implements IDaoSqlTest.Ins
			Const C_SQL As String = "INSERT INTO tbDemoEntities (ID, Code, Name, Note) VALUES (@ID, @ID, 'hoge{0}', 'hoge{0} desu')"
			Dim sql As String = String.Format(C_SQL, id)

			Using cmd As IDbCommandInsert = CreateCommandInsert(sql)
				cmd.SetParameter("ID", id)

				Dim rc As Integer
				rc = cmd.Execute()
			End Using
		End Sub

		Public Sub TimeoutTest(id As Integer, time As Integer) Implements IDaoSqlTest.TimeoutTest
			Dim C_SQL As String = "SELECT * FROM tbDemoEntities WITH (TABLOCKX,HOLDLOCK)"
			Dim sql As String = String.Format(C_SQL)

			Using cmd As IDbCommandSelect = CreateCommandSelect(sql)
				cmd.Execute()

				dao.TimeoutTest(id + 1, time)
			End Using
		End Sub

		Public Function GetHelper() As Moca.Db.IDbAccessHelper Implements IDaoSqlTest.GetHelper
			Return Me.Helper
		End Function

		Public Function GetMe() As Moca.Db.AbstractDao Implements IDaoSqlTest.GetMe
			Return Me
		End Function

	End Class

	Public Class DaoSql2
		Inherits AbstractDao
		Implements IDaoSqlTest2

		Public Sub TimeoutTest(id As Integer, time As Integer) Implements IDaoSqlTest2.TimeoutTest
			Const C_SQL As String = "INSERT INTO tbDemoEntities (ID, Code, Name, Note) VALUES (@ID, @ID, 'hoge{0}', 'hoge{0} desu')"
			Const C_SQL_TIMEOUT As String = "set lock_timeout 0; "
			Dim sql As String = String.Format(C_SQL, id)

			If time = 0 Then
				sql = C_SQL_TIMEOUT & sql
			End If
			Using cmd As IDbCommandInsert = CreateCommandInsert(sql)
				cmd.SetParameter("ID", id)
				If time <> 0 Then
					cmd.Command.CommandTimeout = time
				End If

				Dim rc As Integer
				rc = cmd.Execute()
			End Using
		End Sub

	End Class

#End Region

#Region " SQLCe "

	Public Class DaoSqlCe
		Inherits AbstractDao
		Implements IDaoSqlCeTest

		Protected dao As IDaoSqlCeTest2

#Region " Logging For Log4net "
		''' <summary>Logging For Log4net</summary>
		Private ReadOnly _mylog As log4net.ILog = log4net.LogManager.GetLogger(String.Empty)
#End Region

#Region " コンストラクタ "

		'Public Sub New(ByVal value As String)
		'	MyBase.New(New Dbms(value))
		'End Sub

#End Region

		Public Sub Ins(id As Integer) Implements IDaoSqlCeTest.Ins
			Const C_SQL As String = "INSERT INTO tbDemoEntities (ID, Code, Name, Note) VALUES (@ID, @ID, 'hoge{0}', 'hoge{0} desu')"
			Dim sql As String = String.Format(C_SQL, id)

			Using cmd As IDbCommandInsert = CreateCommandInsert(sql)
				cmd.SetParameter("ID", id)

				Dim rc As Integer
				rc = cmd.Execute()
			End Using
		End Sub

		Public Sub TimeoutTest(id As Integer) Implements IDaoSqlCeTest.TimeoutTest
			Me.Ins(id)
			dao.TimeoutTest(id + 1)
		End Sub

		Public Function GetHelper() As Moca.Db.IDbAccessHelper Implements IDaoSqlCeTest.GetHelper
			Return Me.Helper
		End Function

		Public Function [Select]() As System.Collections.Generic.IList(Of tbDemoEntity) Implements IDaoSqlCeTest.Select
			Const C_SQL As String = "SELECT * FROM tbDemoEntities WHERE ID=@ID"

			Using cmd As IDbCommandSelect = CreateCommandSelect(C_SQL)
				cmd.SetParameter("ID", 2)

				Return cmd.Execute(Of tbDemoEntity)()
			End Using
		End Function

	End Class

	Public Class DaoSqlCe2
		Inherits AbstractDao
		Implements IDaoSqlCeTest2

		Public Sub TimeoutTest(id As Integer) Implements IDaoSqlCeTest2.TimeoutTest
			Const C_SQL As String = "INSERT INTO tbDemoEntities (ID, Code, Name, Note) VALUES (@ID, @ID, 'hoge{0}', 'hoge{0} desu')"
			Dim sql As String = String.Format(C_SQL, id)

			Using cmd As IDbCommandInsert = CreateCommandInsert(sql)
				cmd.SetParameter("ID", id)

				Dim rc As Integer
				rc = cmd.Execute()
			End Using
		End Sub

	End Class

#End Region

#Region " OleDb "

#Region " SQLServer "

	Public Class DaoOleDb
		Inherits AbstractDao
		Implements IDaoOleDbTest

		Protected dao As IDaoOleDbTest2

#Region " Logging For Log4net "
		''' <summary>Logging For Log4net</summary>
		Private ReadOnly _mylog As log4net.ILog = log4net.LogManager.GetLogger(String.Empty)
#End Region

#Region " コンストラクタ "

		'Public Sub New(ByVal value As String)
		'	MyBase.New(New Dbms(value))
		'End Sub

#End Region

		Public Function GetHelper() As Moca.Db.IDbAccessHelper Implements IDaoOleDbTest.GetHelper
			Return Me.Helper
		End Function

		Public Sub Ins(id As Integer) Implements IDaoOleDbTest.Ins
			Const C_SQL As String = "INSERT INTO tbDemoEntities (ID, Code, Name, Note) VALUES (?, ?, 'hoge{0}', 'hoge{0} desu')"
			Dim sql As String = String.Format(C_SQL, id)

			Using cmd As IDbCommandInsert = CreateCommandInsert(sql)
				cmd.SetParameter("ID", id)
				cmd.SetParameter("Code", id)

				Dim rc As Integer
				rc = cmd.Execute()
			End Using
		End Sub

		Public Sub TimeoutTest(id As Integer, time As Integer) Implements IDaoOleDbTest.TimeoutTest
			Dim C_SQL As String = "SELECT * FROM tbDemoEntities WITH (TABLOCKX,HOLDLOCK)"
			Dim sql As String = String.Format(C_SQL)

			Using cmd As IDbCommandSelect = CreateCommandSelect(sql)
				cmd.Execute()

				dao.TimeoutTest(id + 1, time)
			End Using
		End Sub

		Public Function GetMe() As Moca.Db.AbstractDao Implements IDaoOleDbTest.GetMe
			Return Me
		End Function
	End Class

	Public Class DaoOleDb2
		Inherits AbstractDao
		Implements IDaoOleDbTest2

		Public Sub TimeoutTest(id As Integer, time As Integer) Implements IDaoOleDbTest2.TimeoutTest
			Const C_SQL As String = "INSERT INTO tbDemoEntities (ID, Code, Name, Note) VALUES (?, ?, 'hoge{0}', 'hoge{0} desu')"
			Const C_SQL_TIMEOUT As String = "set lock_timeout 0; "
			Dim sql As String = String.Format(C_SQL, id)

			If time = 0 Then
				sql = C_SQL_TIMEOUT & sql
			End If
			Using cmd As IDbCommandInsert = CreateCommandInsert(sql)
				cmd.SetParameter("ID", id)
				cmd.SetParameter("Code", id)
				If time <> 0 Then
					cmd.Command.CommandTimeout = time
				End If

				Dim rc As Integer
				rc = cmd.Execute()
			End Using
		End Sub

	End Class

#End Region
#Region " Oracle "

	Public Class DaoOleDbOra
		Inherits AbstractDao
		Implements IDaoOleDbOraTest

		Protected dao As IDaoOleDbOraTest2

#Region " Logging For Log4net "
		''' <summary>Logging For Log4net</summary>
		Private ReadOnly _mylog As log4net.ILog = log4net.LogManager.GetLogger(String.Empty)
#End Region

#Region " コンストラクタ "

		'Public Sub New(ByVal value As String)
		'	MyBase.New(New Dbms(value))
		'End Sub

#End Region

		Public Function GetHelper() As Moca.Db.IDbAccessHelper Implements IDaoOleDbOraTest.GetHelper
			Return Me.Helper
		End Function

		Public Sub Ins(id As Integer) Implements IDaoOleDbOraTest.Ins
			Const C_SQL As String = "INSERT INTO ""tbDemoEntities"" (ID, ""Code"", ""Name"", ""Note"") VALUES (?, ?, 'hoge{0}', 'hoge{0} desu')"
			Dim sql As String = String.Format(C_SQL, id)

			Using cmd As IDbCommandInsert = CreateCommandInsert(sql)
				cmd.SetParameter("ID", id)
				cmd.SetParameter("Code", id)

				Dim rc As Integer
				rc = cmd.Execute()
			End Using
		End Sub

		Public Sub TimeoutTest(id As Integer, time As Integer) Implements IDaoOleDbOraTest.TimeoutTest
			Dim C_SQL As String = "UPDATE ""tbDemoEntities"" SET ""MSG""='123' WHERE ID=?"

			Using cmd As IDbCommandUpdate = CreateCommandUpdate(C_SQL)
				cmd.SetParameter("ID", id)
				Dim rc As Integer
				rc = cmd.Execute()

				dao.TimeoutTest(id, time)
			End Using
		End Sub

		Public Function GetMe() As Moca.Db.AbstractDao Implements IDaoOleDbOraTest.GetMe
			Return Me
		End Function
	End Class

	Public Class DaoOleDbOra2
		Inherits AbstractDao
		Implements IDaoOleDbOraTest2

		Public Sub TimeoutTest(id As Integer, time As Integer) Implements IDaoOleDbOraTest2.TimeoutTest
			Dim C_SQL As String = "SELECT * FROM ""tbDemoEntities"" WHERE ID=? FOR UPDATE "
			Dim sql As String

			If time = 0 Then
				sql = C_SQL & "NOWAIT"
			Else
				sql = C_SQL & "WAIT " & time
			End If

			Using cmd As IDbCommandSelect = CreateCommandSelect(sql)
				cmd.SetParameter("ID", id)

				cmd.Execute()
			End Using
		End Sub

	End Class

#End Region

#End Region

#Region " Oracle "

    Public Class DaoOracle
        Inherits AbstractDao
        Implements IDaoOracleTest

        Protected dao As IDaoOracleTest2

#Region " Logging For Log4net "
        ''' <summary>Logging For Log4net</summary>
        Private ReadOnly _mylog As log4net.ILog = log4net.LogManager.GetLogger(String.Empty)
#End Region

#Region " コンストラクタ "

        'Public Sub New(ByVal value As String)
        '	MyBase.New(New Dbms(value))
        'End Sub

#End Region

        Public Sub Ins(id As Integer) Implements IDaoOracleTest.Ins
            Const C_SQL As String = "INSERT INTO ""tbDemoEntities"" (ID, ""Code"", ""Name"", ""Note"") VALUES (:ID, :Code, 'hoge{0}', 'hoge{0} desu')"
            Dim sql As String = String.Format(C_SQL, id)

            Using cmd As IDbCommandInsert = CreateCommandInsert(sql)
                cmd.SetParameter("ID", id)
                cmd.SetParameter("Code", id)

                Dim rc As Integer
                rc = cmd.Execute()
            End Using
        End Sub

        Public Function GetHelper() As Moca.Db.IDbAccessHelper Implements IDaoOracleTest.GetHelper
            Return Me.Helper
        End Function

        Public Function GetMe() As Moca.Db.AbstractDao Implements IDaoOracleTest.GetMe
            Return Me
        End Function

        Public Sub TimeoutTest(id As Integer, time As Integer) Implements IDaoOracleTest.TimeoutTest
            Dim C_SQL As String = "UPDATE ""tbDemoEntities"" SET ""MSG""='123' WHERE ID=:ID"

            Using cmd As IDbCommandUpdate = CreateCommandUpdate(C_SQL)
                cmd.SetParameter("ID", id)
                Dim rc As Integer
                rc = cmd.Execute()

                dao.TimeoutTest(id, time)
            End Using
        End Sub

    End Class

    Public Class DaoOracleManaged
        Inherits AbstractDao
        Implements IDaoOracleManagedTest

        Protected dao As IDaoOracleTest2

#Region " Logging For Log4net "
        ''' <summary>Logging For Log4net</summary>
        Private ReadOnly _mylog As log4net.ILog = log4net.LogManager.GetLogger(String.Empty)
#End Region

#Region " コンストラクタ "

        'Public Sub New(ByVal value As String)
        '	MyBase.New(New Dbms(value))
        'End Sub

#End Region

        Public Sub Ins(id As Integer) Implements IDaoOracleManagedTest.Ins
            Const C_SQL As String = "INSERT INTO ""tbDemoEntities"" (ID, ""Code"", ""Name"", ""Note"") VALUES (:ID, :Code, 'hoge{0}', 'hoge{0} desu')"
            Dim sql As String = String.Format(C_SQL, id)

            Using cmd As IDbCommandInsert = CreateCommandInsert(sql)
                cmd.SetParameter("ID", id)
                cmd.SetParameter("Code", id)

                Dim rc As Integer
                rc = cmd.Execute()
            End Using
        End Sub

        Public Function GetHelper() As Moca.Db.IDbAccessHelper Implements IDaoOracleManagedTest.GetHelper
            Return Me.Helper
        End Function

        Public Function GetMe() As Moca.Db.AbstractDao Implements IDaoOracleManagedTest.GetMe
            Return Me
        End Function

        Public Sub TimeoutTest(id As Integer, time As Integer) Implements IDaoOracleManagedTest.TimeoutTest
            Dim C_SQL As String = "UPDATE ""tbDemoEntities"" SET ""MSG""='123' WHERE ID=:ID"

            Using cmd As IDbCommandUpdate = CreateCommandUpdate(C_SQL)
                cmd.SetParameter("ID", id)
                Dim rc As Integer
                rc = cmd.Execute()

                dao.TimeoutTest(id, time)
            End Using
        End Sub
    End Class

    Public Class DaoOracle2
        Inherits AbstractDao
        Implements IDaoOracleTest2

        Public Sub TimeoutTest(id As Integer, time As Integer) Implements IDaoOracleTest2.TimeoutTest
            Dim C_SQL As String = "SELECT * FROM ""tbDemoEntities"" WHERE ID=:ID FOR UPDATE "
            Dim sql As String

            If time = 0 Then
                sql = C_SQL & "NOWAIT"
            Else
                sql = C_SQL & "WAIT " & time
            End If

            Using cmd As IDbCommandSelect = CreateCommandSelect(sql)
                cmd.SetParameter("ID", id)

                cmd.Execute()
            End Using
        End Sub

    End Class

#End Region

#Region " Oracle MS "

    Public Class DaoOracleMS
        Inherits AbstractDao
        Implements IDaoOracleMSTest

        Protected dao As IDaoOracleMSTest2

#Region " Logging For Log4net "
        ''' <summary>Logging For Log4net</summary>
        Private ReadOnly _mylog As log4net.ILog = log4net.LogManager.GetLogger(String.Empty)
#End Region

#Region " コンストラクタ "

        'Public Sub New(ByVal value As String)
        '	MyBase.New(New Dbms(value))
        'End Sub

#End Region

        Public Sub Ins(id As Integer) Implements IDaoOracleMSTest.Ins
            Const C_SQL As String = "INSERT INTO ""tbDemoEntities"" (ID, ""Code"", ""Name"", ""Note"") VALUES (:ID, :Code, 'hoge{0}', 'hoge{0} desu')"
            Dim sql As String = String.Format(C_SQL, id)

            Using cmd As IDbCommandInsert = CreateCommandInsert(sql)
                cmd.SetParameter("ID", id)
                cmd.SetParameter("Code", id)

                Dim rc As Integer
                rc = cmd.Execute()
            End Using
        End Sub

        Public Function GetHelper() As Moca.Db.IDbAccessHelper Implements IDaoOracleMSTest.GetHelper
            Return Me.Helper
        End Function

        Public Function GetMe() As Moca.Db.AbstractDao Implements IDaoOracleMSTest.GetMe
            Return Me
        End Function

        Public Sub TimeoutTest(id As Integer, time As Integer) Implements IDaoOracleMSTest.TimeoutTest
            Dim C_SQL As String = "UPDATE ""tbDemoEntities"" SET ""MSG""='123' WHERE ID=:ID"

            Using cmd As IDbCommandUpdate = CreateCommandUpdate(C_SQL)
                cmd.SetParameter("ID", id)
                Dim rc As Integer
                rc = cmd.Execute()

                dao.TimeoutTest(id, time)
            End Using
        End Sub

    End Class

    Public Class DaoOracleMS2
        Inherits AbstractDao
        Implements IDaoOracleMSTest2

        Public Sub TimeoutTest(id As Integer, time As Integer) Implements IDaoOracleMSTest2.TimeoutTest
            Dim C_SQL As String = "SELECT * FROM ""tbDemoEntities"" WHERE ID=:ID FOR UPDATE "
            Dim sql As String

            If time = 0 Then
                sql = C_SQL & "NOWAIT"
            Else
                sql = C_SQL & "WAIT " & time
            End If

            Using cmd As IDbCommandSelect = CreateCommandSelect(sql)
                cmd.SetParameter("ID", id)

                cmd.Execute()
            End Using
        End Sub

    End Class

#End Region

End Namespace
